<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/zxy12666.github.io/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/zxy12666.github.io/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/zxy12666.github.io/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/zxy12666.github.io/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/zxy12666.github.io/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/zxy12666.github.io/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/zxy12666.github.io/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/zxy12666.github.io/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/zxy12666.github.io/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="vue,">










<meta name="description" content="一、效果图二、封装两个组件，分别为DynamicTable.vue和TableColumn.vue，TableColumn.vue主要是使用递归来对表头进行循环生成DynamicTable.vue 1 &amp;lt;template&amp;gt; 2   &amp;lt;el-table :data=”tableData” border :height=”height”&amp;gt; 3     &amp;lt;template">
<meta name="keywords" content="vue">
<meta property="og:type" content="article">
<meta property="og:title" content="element UI实现动态生成多级表头">
<meta property="og:url" content="https://zxy12666.gitee.io/zxy12666.github.io/2019/05/05/element-UI实现动态生成多级表头/index.html">
<meta property="og:site_name" content="张翔宇博客">
<meta property="og:description" content="一、效果图二、封装两个组件，分别为DynamicTable.vue和TableColumn.vue，TableColumn.vue主要是使用递归来对表头进行循环生成DynamicTable.vue 1 &amp;lt;template&amp;gt; 2   &amp;lt;el-table :data=”tableData” border :height=”height”&amp;gt; 3     &amp;lt;template">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://i1.fuimg.com/691375/95ac80c22df10c32.png">
<meta property="og:image" content="http://i1.fuimg.com/691375/0700d9700a435779s.png">
<meta property="og:image" content="https://common.cnblogs.com/images/copycode.gif">
<meta property="og:updated_time" content="2019-06-21T02:57:21.666Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="element UI实现动态生成多级表头">
<meta name="twitter:description" content="一、效果图二、封装两个组件，分别为DynamicTable.vue和TableColumn.vue，TableColumn.vue主要是使用递归来对表头进行循环生成DynamicTable.vue 1 &amp;lt;template&amp;gt; 2   &amp;lt;el-table :data=”tableData” border :height=”height”&amp;gt; 3     &amp;lt;template">
<meta name="twitter:image" content="http://i1.fuimg.com/691375/95ac80c22df10c32.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/zxy12666.github.io/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zxy12666.gitee.io/zxy12666.github.io/2019/05/05/element-UI实现动态生成多级表头/">






  <title>element UI实现动态生成多级表头 | 张翔宇博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/zxy12666.github.io/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">张翔宇博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/zxy12666.github.io/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/zxy12666.github.io/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/zxy12666.github.io/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/zxy12666.github.io/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/zxy12666.github.io/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zxy12666.gitee.io/zxy12666.github.io/zxy12666.github.io/2019/05/05/element-UI实现动态生成多级表头/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="张翔宇">
      <meta itemprop="description" content>
      <meta itemprop="image" content="http://sunui-uniapp.oss-cn-beijing.aliyuncs.com/uniapp/15603254900059.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="张翔宇博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">element UI实现动态生成多级表头</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-05-05T09:15:00+08:00">
                2019-05-05
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/zxy12666.github.io/categories/vue/" itemprop="url" rel="index">
                    <span itemprop="name">vue</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/zxy12666.github.io/2019/05/05/element-UI实现动态生成多级表头/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2019/05/05/element-UI实现动态生成多级表头/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <div class="post"><br><br><strong>一、效果图</strong><br><br><img src="http://i1.fuimg.com/691375/95ac80c22df10c32.png" alt="Markdown"><br><br><img src="http://i1.fuimg.com/691375/0700d9700a435779s.png" alt="Markdown"><br><br><strong>二、封装两个组件，分别为DynamicTable.vue和TableColumn.vue，TableColumn.vue主要是使用递归来对表头进行循环生成</strong><br><br>DynamicTable.vue<br><br><br><pre><span style="color: #008080;"> 1</span> &lt;template&gt;<br><span style="color: #008080;"> 2</span>   &lt;el-table :data=”tableData” border :height=”height”&gt;<br><span style="color: #008080;"> 3</span>     &lt;template v-<span style="color: #0000ff;">for</span>=”item in tableHeader”&gt;<br><span style="color: #008080;"> 4</span>       &lt;table-column v-<span style="color: #0000ff;">if</span>=”item.children &amp;&amp; item.children.length” :key=”item.id” :coloumn-header=”item”&gt;&lt;/table-column&gt;<br><span style="color: #008080;"> 5</span>       &lt;el-table-column v-<span style="color: #0000ff;">else</span> :key=”item.id” :label=”item.label” :prop=”item.prop” align=”center”&gt;&lt;/el-table-column&gt;<br><span style="color: #008080;"> 6</span>     &lt;/template&gt;<br><span style="color: #008080;"> 7</span>   &lt;/el-table&gt;<br><span style="color: #008080;"> 8</span> &lt;/template&gt;<br><span style="color: #008080;"> 9</span><br><span style="color: #008080;">10</span> &lt;script&gt;<br><span style="color: #008080;">11</span> import TableColumn from ‘./TableColumn’<br><span style="color: #008080;">12</span> export <span style="color: #0000ff;">default</span><span style="color: #000000;"> {<br></span><span style="color: #008080;">13</span> <span style="color: #000000;">  props: {<br></span><span style="color: #008080;">14</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 表格的数据</span><br><span style="color: #008080;">15</span> <span style="color: #000000;">    tableData: {<br></span><span style="color: #008080;">16</span> <span style="color: #000000;">      type: Array,<br></span><span style="color: #008080;">17</span>       required: <span style="color: #0000ff;">true</span><br><span style="color: #008080;">18</span> <span style="color: #000000;">    },<br></span><span style="color: #008080;">19</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 多级表头的数据</span><br><span style="color: #008080;">20</span> <span style="color: #000000;">    tableHeader: {<br></span><span style="color: #008080;">21</span> <span style="color: #000000;">      type: Array,<br></span><span style="color: #008080;">22</span>       required: <span style="color: #0000ff;">true</span><br><span style="color: #008080;">23</span> <span style="color: #000000;">    },<br></span><span style="color: #008080;">24</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 表格的高度</span><br><span style="color: #008080;">25</span> <span style="color: #000000;">    height: {<br></span><span style="color: #008080;">26</span> <span style="color: #000000;">      type: String,<br></span><span style="color: #008080;">27</span>       <span style="color: #0000ff;">default</span>: ‘300’<br><span style="color: #008080;">28</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">29</span> <span style="color: #000000;">  },<br></span><span style="color: #008080;">30</span> <span style="color: #000000;">  components: {<br></span><span style="color: #008080;">31</span> <span style="color: #000000;">    TableColumn<br></span><span style="color: #008080;">32</span> <span style="color: #000000;">  }<br></span><span style="color: #008080;">33</span> <span style="color: #000000;">}<br></span><span style="color: #008080;">34</span> &lt;/script&gt;<br><span style="color: #008080;">35</span><br><span style="color: #008080;">36</span> &lt;style scoped&gt;<br><span style="color: #008080;">37</span><br><span style="color: #008080;">38</span> &lt;/style&gt;</pre><br><div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy"><a href="javascript:void(0" target="_blank" rel="noopener"><img src="//common.cnblogs.com/images/copycode.gif" alt="复制代码"></a>; “复制代码”)</span></div></div>

<p>TableColumn.vue</p>
<pre>&lt;template&gt;
  &lt;el-table-column :label="coloumnHeader.label" :prop="coloumnHeader.label" align="center"&gt;
    &lt;template v-<span style="color: #0000ff;">for</span>="item in coloumnHeader.children"&gt;
      &lt;tableColumn v-<span style="color: #0000ff;">if</span>="item.children &amp;&amp; item.children.length" :key="item.id" :coloumn-header="item"&gt;&lt;/tableColumn&gt;
      &lt;el-table-column v-<span style="color: #0000ff;">else</span> :key="item.name" :label="item.label" :prop="item.prop" align="center"&gt;&lt;/el-table-column&gt;
    &lt;/template&gt;
  &lt;/el-table-column&gt;
&lt;/template&gt;

&lt;script&gt;<span style="color: #000000;">
export </span><span style="color: #0000ff;">default</span><span style="color: #000000;"> {
  name: </span>'tableColumn'<span style="color: #000000;">,
  props: {
    coloumnHeader: {
      type: Object,
      required: </span><span style="color: #0000ff;">true</span><span style="color: #000000;">
    }
  }
}
</span>&lt;/script&gt;

&lt;style scoped&gt;

&lt;/style&gt;</pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy">[![复制代码](//common.cnblogs.com/images/copycode.gif)](javascript:void(0); "复制代码")</span></div>

**三、使用**

HTML代码

<div class="cnblogs_code">
<pre><span style="color: #008080;">1</span>     &lt;div class="result-wrapper"&gt;
<span style="color: #008080;">2</span>       &lt;dynamic-table :table-data="tableData" :table-header="tableConfig" v-<span style="color: #0000ff;">if</span>="dynamicTableShow"&gt;&lt;/dynamic-table&gt;
<span style="color: #008080;">3</span>       &lt;dynamic-form v-<span style="color: #0000ff;">else</span>&gt;&lt;/dynamic-form&gt;
<span style="color: #008080;">4</span>     &lt;/div&gt;</pre>
</div>

JS代码


<pre><span style="color: #008080;">  1</span> &lt;script&gt;
<span style="color: #008080;">  2</span> import DynamicTable from './components/DynamicTable'
<span style="color: #008080;">  3</span> export <span style="color: #0000ff;">default</span><span style="color: #000000;"> {
</span><span style="color: #008080;">  4</span> <span style="color: #000000;">  components: {
</span><span style="color: #008080;">  5</span> <span style="color: #000000;">    DynamicTable
</span><span style="color: #008080;">  6</span> <span style="color: #000000;">  },
</span><span style="color: #008080;">  7</span> <span style="color: #000000;">  data () {
</span><span style="color: #008080;">  8</span>     <span style="color: #0000ff;">return</span><span style="color: #000000;"> {
</span><span style="color: #008080;">  9</span> <span style="color: #000000;">      searchForm: {
</span><span style="color: #008080;"> 10</span> <span style="color: #000000;">        month: getMonth(),
</span><span style="color: #008080;"> 11</span>         serviceCategory: '1'
<span style="color: #008080;"> 12</span> <span style="color: #000000;">      },
</span><span style="color: #008080;"> 13</span>       dynamicTableShow: <span style="color: #0000ff;">true</span>, <span style="color: #008000;">//</span><span style="color: #008000;"> 使得DynamicTable组件重新渲染变量</span>
<span style="color: #008080;"> 14</span>       <span style="color: #008000;">//</span><span style="color: #008000;"> 表数据</span>
<span style="color: #008080;"> 15</span> <span style="color: #000000;">      tableData: [
</span><span style="color: #008080;"> 16</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 17</span>           districtName: '1'<span style="color: #000000;">,
</span><span style="color: #008080;"> 18</span>           timeDimension: '2'<span style="color: #000000;">,
</span><span style="color: #008080;"> 19</span>           residentPopNum: '3'<span style="color: #000000;">,
</span><span style="color: #008080;"> 20</span>           residentPopDst: '4'<span style="color: #000000;">,
</span><span style="color: #008080;"> 21</span>           liveLandArea: '5'<span style="color: #000000;">,
</span><span style="color: #008080;"> 22</span>           liveLandDst: '6'<span style="color: #000000;">,
</span><span style="color: #008080;"> 23</span>           employmentLandArea: '7'<span style="color: #000000;">,
</span><span style="color: #008080;"> 24</span>           employmentLandDst: '8'
<span style="color: #008080;"> 25</span> <span style="color: #000000;">        }
</span><span style="color: #008080;"> 26</span> <span style="color: #000000;">      ],
</span><span style="color: #008080;"> 27</span>       <span style="color: #008000;">//</span><span style="color: #008000;"> 表头数据</span>
<span style="color: #008080;"> 28</span> <span style="color: #000000;">      tableConfig: [
</span><span style="color: #008080;"> 29</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 30</span>           id: 100<span style="color: #000000;">,
</span><span style="color: #008080;"> 31</span>           label: '一级表头'<span style="color: #000000;">,
</span><span style="color: #008080;"> 32</span>           prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 33</span> <span style="color: #000000;">          children: [
</span><span style="color: #008080;"> 34</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 35</span>               id: 110<span style="color: #000000;">,
</span><span style="color: #008080;"> 36</span>               label: '二级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;"> 37</span>               prop: 'districtName'
<span style="color: #008080;"> 38</span> <span style="color: #000000;">            },
</span><span style="color: #008080;"> 39</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 40</span>               id: 120<span style="color: #000000;">,
</span><span style="color: #008080;"> 41</span>               label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;"> 42</span>               prop: 'timeDimension'
<span style="color: #008080;"> 43</span> <span style="color: #000000;">            }
</span><span style="color: #008080;"> 44</span> <span style="color: #000000;">          ]
</span><span style="color: #008080;"> 45</span> <span style="color: #000000;">        },
</span><span style="color: #008080;"> 46</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 47</span>           id: 200<span style="color: #000000;">,
</span><span style="color: #008080;"> 48</span>           label: '一级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;"> 49</span>           prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 50</span> <span style="color: #000000;">          children: [
</span><span style="color: #008080;"> 51</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 52</span>               id: 210<span style="color: #000000;">,
</span><span style="color: #008080;"> 53</span>               label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;"> 54</span>               prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 55</span> <span style="color: #000000;">              children: [
</span><span style="color: #008080;"> 56</span> <span style="color: #000000;">                {
</span><span style="color: #008080;"> 57</span>                   id: 211<span style="color: #000000;">,
</span><span style="color: #008080;"> 58</span>                   label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;"> 59</span>                   prop: 'residentPopNum'
<span style="color: #008080;"> 60</span> <span style="color: #000000;">                },
</span><span style="color: #008080;"> 61</span> <span style="color: #000000;">                {
</span><span style="color: #008080;"> 62</span>                   id: 212<span style="color: #000000;">,
</span><span style="color: #008080;"> 63</span>                   label: '三级表头'<span style="color: #000000;">,
</span><span style="color: #008080;"> 64</span>                   prop: 'residentPopDst'
<span style="color: #008080;"> 65</span> <span style="color: #000000;">                }
</span><span style="color: #008080;"> 66</span> <span style="color: #000000;">              ]
</span><span style="color: #008080;"> 67</span> <span style="color: #000000;">            }
</span><span style="color: #008080;"> 68</span> <span style="color: #000000;">          ]
</span><span style="color: #008080;"> 69</span> <span style="color: #000000;">        },
</span><span style="color: #008080;"> 70</span> <span style="color: #000000;">        {
</span><span style="color: #008080;"> 71</span>           id: 300<span style="color: #000000;">,
</span><span style="color: #008080;"> 72</span>           label: '一级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;"> 73</span>           prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 74</span> <span style="color: #000000;">          children: [
</span><span style="color: #008080;"> 75</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 76</span>               id: 310<span style="color: #000000;">,
</span><span style="color: #008080;"> 77</span>               label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;"> 78</span>               prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 79</span> <span style="color: #000000;">              children: [
</span><span style="color: #008080;"> 80</span> <span style="color: #000000;">                {
</span><span style="color: #008080;"> 81</span>                   id: 311<span style="color: #000000;">,
</span><span style="color: #008080;"> 82</span>                   label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;"> 83</span>                   prop: 'liveLandArea'
<span style="color: #008080;"> 84</span> <span style="color: #000000;">                },
</span><span style="color: #008080;"> 85</span> <span style="color: #000000;">                {
</span><span style="color: #008080;"> 86</span>                   id: 312<span style="color: #000000;">,
</span><span style="color: #008080;"> 87</span>                   label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;"> 88</span>                   prop: 'liveLandDst'
<span style="color: #008080;"> 89</span> <span style="color: #000000;">                }
</span><span style="color: #008080;"> 90</span> <span style="color: #000000;">              ]
</span><span style="color: #008080;"> 91</span> <span style="color: #000000;">            },
</span><span style="color: #008080;"> 92</span> <span style="color: #000000;">            {
</span><span style="color: #008080;"> 93</span>               id: 320<span style="color: #000000;">,
</span><span style="color: #008080;"> 94</span>               label: '二级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;"> 95</span>               prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;"> 96</span> <span style="color: #000000;">              children: [
</span><span style="color: #008080;"> 97</span> <span style="color: #000000;">                {
</span><span style="color: #008080;"> 98</span>                   id: 321<span style="color: #000000;">,
</span><span style="color: #008080;"> 99</span>                   label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">100</span>                   prop: 'employmentLandArea'
<span style="color: #008080;">101</span> <span style="color: #000000;">                },
</span><span style="color: #008080;">102</span> <span style="color: #000000;">                {
</span><span style="color: #008080;">103</span>                   id: 322<span style="color: #000000;">,
</span><span style="color: #008080;">104</span>                   label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">105</span>                   prop: 'employmentLandDst'
<span style="color: #008080;">106</span> <span style="color: #000000;">                }
</span><span style="color: #008080;">107</span> <span style="color: #000000;">              ]
</span><span style="color: #008080;">108</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">109</span> <span style="color: #000000;">          ]
</span><span style="color: #008080;">110</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">111</span> <span style="color: #000000;">      ]
</span><span style="color: #008080;">112</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">113</span> <span style="color: #000000;">  },
</span><span style="color: #008080;">114</span> <span style="color: #000000;">  methods: {
</span><span style="color: #008080;">115</span>     <span style="color: #008000;">//</span><span style="color: #008000;"> 服务类型改变的时候，需要重新请求表头信息和表格数据</span>
<span style="color: #008080;">116</span> <span style="color: #000000;">    handleServiceCategoryChange (val) {
</span><span style="color: #008080;">117</span>       <span style="color: #008000;">//</span><span style="color: #008000;"> 设置dynamicTableShow为false，使得DynamicTable组件重新渲染</span>
<span style="color: #008080;">118</span>       <span style="color: #0000ff;">this</span>.dynamicTableShow = <span style="color: #0000ff;">false</span>
<span style="color: #008080;">119</span>       <span style="color: #0000ff;">if</span> (val === '1'<span style="color: #000000;">) {
</span><span style="color: #008080;">120</span>         <span style="color: #0000ff;">this</span>.tableData =<span style="color: #000000;"> [
</span><span style="color: #008080;">121</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">122</span>             districtName: '1'<span style="color: #000000;">,
</span><span style="color: #008080;">123</span>             timeDimension: '2'<span style="color: #000000;">,
</span><span style="color: #008080;">124</span>             residentPopNum: '3'<span style="color: #000000;">,
</span><span style="color: #008080;">125</span>             residentPopDst: '4'<span style="color: #000000;">,
</span><span style="color: #008080;">126</span>             liveLandArea: '5'<span style="color: #000000;">,
</span><span style="color: #008080;">127</span>             liveLandDst: '6'<span style="color: #000000;">,
</span><span style="color: #008080;">128</span>             employmentLandArea: '7'<span style="color: #000000;">,
</span><span style="color: #008080;">129</span>             employmentLandDst: '8'
<span style="color: #008080;">130</span> <span style="color: #000000;">          }
</span><span style="color: #008080;">131</span> <span style="color: #000000;">        ]
</span><span style="color: #008080;">132</span>         <span style="color: #0000ff;">this</span>.tableConfig =<span style="color: #000000;"> [
</span><span style="color: #008080;">133</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">134</span>             id: 100<span style="color: #000000;">,
</span><span style="color: #008080;">135</span>             label: '一级表头'<span style="color: #000000;">,
</span><span style="color: #008080;">136</span>             prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">137</span> <span style="color: #000000;">            children: [
</span><span style="color: #008080;">138</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">139</span>                 id: 110<span style="color: #000000;">,
</span><span style="color: #008080;">140</span>                 label: '二级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;">141</span>                 prop: 'districtName'
<span style="color: #008080;">142</span> <span style="color: #000000;">              },
</span><span style="color: #008080;">143</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">144</span>                 id: 120<span style="color: #000000;">,
</span><span style="color: #008080;">145</span>                 label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;">146</span>                 prop: 'timeDimension'
<span style="color: #008080;">147</span> <span style="color: #000000;">              }
</span><span style="color: #008080;">148</span> <span style="color: #000000;">            ]
</span><span style="color: #008080;">149</span> <span style="color: #000000;">          },
</span><span style="color: #008080;">150</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">151</span>             id: 200<span style="color: #000000;">,
</span><span style="color: #008080;">152</span>             label: '一级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;">153</span>             prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">154</span> <span style="color: #000000;">            children: [
</span><span style="color: #008080;">155</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">156</span>                 id: 210<span style="color: #000000;">,
</span><span style="color: #008080;">157</span>                 label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;">158</span>                 prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">159</span> <span style="color: #000000;">                children: [
</span><span style="color: #008080;">160</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">161</span>                     id: 211<span style="color: #000000;">,
</span><span style="color: #008080;">162</span>                     label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">163</span>                     prop: 'residentPopNum'
<span style="color: #008080;">164</span> <span style="color: #000000;">                  },
</span><span style="color: #008080;">165</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">166</span>                     id: 212<span style="color: #000000;">,
</span><span style="color: #008080;">167</span>                     label: '三级表头'<span style="color: #000000;">,
</span><span style="color: #008080;">168</span>                     prop: 'residentPopDst'
<span style="color: #008080;">169</span> <span style="color: #000000;">                  }
</span><span style="color: #008080;">170</span> <span style="color: #000000;">                ]
</span><span style="color: #008080;">171</span> <span style="color: #000000;">              }
</span><span style="color: #008080;">172</span> <span style="color: #000000;">            ]
</span><span style="color: #008080;">173</span> <span style="color: #000000;">          },
</span><span style="color: #008080;">174</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">175</span>             id: 300<span style="color: #000000;">,
</span><span style="color: #008080;">176</span>             label: '一级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;">177</span>             prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">178</span> <span style="color: #000000;">            children: [
</span><span style="color: #008080;">179</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">180</span>                 id: 310<span style="color: #000000;">,
</span><span style="color: #008080;">181</span>                 label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;">182</span>                 prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">183</span> <span style="color: #000000;">                children: [
</span><span style="color: #008080;">184</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">185</span>                     id: 311<span style="color: #000000;">,
</span><span style="color: #008080;">186</span>                     label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">187</span>                     prop: 'liveLandArea'
<span style="color: #008080;">188</span> <span style="color: #000000;">                  },
</span><span style="color: #008080;">189</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">190</span>                     id: 312<span style="color: #000000;">,
</span><span style="color: #008080;">191</span>                     label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">192</span>                     prop: 'liveLandDst'
<span style="color: #008080;">193</span> <span style="color: #000000;">                  }
</span><span style="color: #008080;">194</span> <span style="color: #000000;">                ]
</span><span style="color: #008080;">195</span> <span style="color: #000000;">              },
</span><span style="color: #008080;">196</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">197</span>                 id: 320<span style="color: #000000;">,
</span><span style="color: #008080;">198</span>                 label: '二级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;">199</span>                 prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">200</span> <span style="color: #000000;">                children: [
</span><span style="color: #008080;">201</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">202</span>                     id: 321<span style="color: #000000;">,
</span><span style="color: #008080;">203</span>                     label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">204</span>                     prop: 'employmentLandArea'
<span style="color: #008080;">205</span> <span style="color: #000000;">                  },
</span><span style="color: #008080;">206</span> <span style="color: #000000;">                  {
</span><span style="color: #008080;">207</span>                     id: 322<span style="color: #000000;">,
</span><span style="color: #008080;">208</span>                     label: '三级表头3'<span style="color: #000000;">,
</span><span style="color: #008080;">209</span>                     prop: 'employmentLandDst'
<span style="color: #008080;">210</span> <span style="color: #000000;">                  }
</span><span style="color: #008080;">211</span> <span style="color: #000000;">                ]
</span><span style="color: #008080;">212</span> <span style="color: #000000;">              }
</span><span style="color: #008080;">213</span> <span style="color: #000000;">            ]
</span><span style="color: #008080;">214</span> <span style="color: #000000;">          }
</span><span style="color: #008080;">215</span> <span style="color: #000000;">        ]
</span><span style="color: #008080;">216</span>       } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {
</span><span style="color: #008080;">217</span>         <span style="color: #0000ff;">this</span>.tableData =<span style="color: #000000;"> [
</span><span style="color: #008080;">218</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">219</span>             districtName: '111'<span style="color: #000000;">,
</span><span style="color: #008080;">220</span>             timeDimension: '222'
<span style="color: #008080;">221</span> <span style="color: #000000;">          }
</span><span style="color: #008080;">222</span> <span style="color: #000000;">        ]
</span><span style="color: #008080;">223</span>         <span style="color: #0000ff;">this</span>.tableConfig =<span style="color: #000000;"> [
</span><span style="color: #008080;">224</span> <span style="color: #000000;">          {
</span><span style="color: #008080;">225</span>             id: 100<span style="color: #000000;">,
</span><span style="color: #008080;">226</span>             label: '一级表头'<span style="color: #000000;">,
</span><span style="color: #008080;">227</span>             prop: ''<span style="color: #000000;">,
</span><span style="color: #008080;">228</span> <span style="color: #000000;">            children: [
</span><span style="color: #008080;">229</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">230</span>                 id: 110<span style="color: #000000;">,
</span><span style="color: #008080;">231</span>                 label: '二级表头1'<span style="color: #000000;">,
</span><span style="color: #008080;">232</span>                 prop: 'districtName'
<span style="color: #008080;">233</span> <span style="color: #000000;">              },
</span><span style="color: #008080;">234</span> <span style="color: #000000;">              {
</span><span style="color: #008080;">235</span>                 id: 120<span style="color: #000000;">,
</span><span style="color: #008080;">236</span>                 label: '二级表头2'<span style="color: #000000;">,
</span><span style="color: #008080;">237</span>                 prop: 'timeDimension'
<span style="color: #008080;">238</span> <span style="color: #000000;">              }
</span><span style="color: #008080;">239</span> <span style="color: #000000;">            ]
</span><span style="color: #008080;">240</span> <span style="color: #000000;">          }
</span><span style="color: #008080;">241</span> <span style="color: #000000;">        ]
</span><span style="color: #008080;">242</span> <span style="color: #000000;">      }
</span><span style="color: #008080;">243</span>       <span style="color: #008000;">//</span><span style="color: #008000;"> 此处是DOM还没有更新，此处的代码是必须的</span>
<span style="color: #008080;">244</span>       <span style="color: #0000ff;">this</span>.$nextTick(() =&gt;<span style="color: #000000;"> {
</span><span style="color: #008080;">245</span>         <span style="color: #008000;">//</span><span style="color: #008000;"> DOM 现在更新了</span>
<span style="color: #008080;">246</span>         <span style="color: #0000ff;">this</span>.dynamicTableShow = <span style="color: #0000ff;">true</span>
<span style="color: #008080;">247</span> <span style="color: #000000;">      })
</span><span style="color: #008080;">248</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">249</span> <span style="color: #000000;">  }
</span><span style="color: #008080;">250</span> <span style="color: #000000;">}
</span><span style="color: #008080;">251</span> &lt;/script&gt;
<span style="color: #008080;">252</span> 
<span style="color: #008080;">253</span> &lt;style scoped&gt;
<span style="color: #008080;">254</span> .policy-<span style="color: #000000;">wrapper{
</span><span style="color: #008080;">255</span>   margin-<span style="color: #000000;">top: 10px;
</span><span style="color: #008080;">256</span> <span style="color: #000000;">}
</span><span style="color: #008080;">257</span> .result-<span style="color: #000000;">wrapper{
</span><span style="color: #008080;">258</span>   margin-<span style="color: #000000;">top: 22px;
</span><span style="color: #008080;">259</span> <span style="color: #000000;">}
</span><span style="color: #008080;">260</span> &lt;/style&gt;</pre>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/zxy12666.github.io/tags/vue/" rel="tag"># vue</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/zxy12666.github.io/2019/03/08/flutter踩坑记录之IOS输入框长按报错/" rel="next" title="flutter踩坑记录之IOS输入框长按报错">
                <i class="fa fa-chevron-left"></i> flutter踩坑记录之IOS输入框长按报错
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/zxy12666.github.io/2019/05/16/Flutter国际化设置在iOS设备上不生效的问题/" rel="prev" title="Flutter国际化设置在iOS设备上不生效的问题">
                Flutter国际化设置在iOS设备上不生效的问题 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div class="ds-thread" data-thread-key="2019/05/05/element-UI实现动态生成多级表头/" data-title="element UI实现动态生成多级表头" data-url="https://zxy12666.gitee.io/zxy12666.github.io/2019/05/05/element-UI实现动态生成多级表头/">
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="http://sunui-uniapp.oss-cn-beijing.aliyuncs.com/uniapp/15603254900059.png" alt="张翔宇">
            
              <p class="site-author-name" itemprop="name">张翔宇</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/zxy12666.github.io/archives/">
              
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/zxy12666.github.io/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/zxy12666.github.io/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zxy12666" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">张翔宇</span>

  
</div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/zxy12666.github.io/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/zxy12666.github.io/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/zxy12666.github.io/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/zxy12666.github.io/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/zxy12666.github.io/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/zxy12666.github.io/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/zxy12666.github.io/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/zxy12666.github.io/js/src/bootstrap.js?v=5.1.4"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"your-duoshuo-shortname"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/zxy12666.github.io/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/zxy12666.github.io/js/src/hook-duoshuo.js"></script>
  
















  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: true,
        appId: 'JvFV9uFfrAsFnxIMs7lVUWgG-gzGzoHsz',
        appKey: 'St5sWGk4OUHFxDnaMtgN2GNd',
        placeholder: '留言区',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/zxy12666.github.io/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

<script src="/zxy12666.github.io/live2dw/lib/L2Dwidget.min.js?0c58a1486de42ac6cc1c59c7d98ae887"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/zxy12666.github.io/live2dw/assets/shizuku.model.json"},"display":{"position":"right","width":100,"height":150},"mobile":{"show":false},"react":{"opacityDefault":1,"opacityOnHover":1},"log":false});</script></body>
</html>
